package com.hj.aiagent.tools;

import jakarta.annotation.Resource;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;


/**
 * 邮件发送工具
 */
@Component
public class MailSendTool {

    @Resource
    private JavaMailSender mailSender;

    @Value("${spring.mail.username}")
    private String fromMail;

    @Tool(description = "Send an email to the specified recipient")
    public String sendMail(
            @ToolParam(description = "Recipient's email address") String to,
            @ToolParam(description = "Email subject") String subject,
            @ToolParam(description = "Email content") String content) {
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(fromMail);
            message.setTo(to);
            message.setSubject(subject);
            message.setText(content);
            mailSender.send(message);
            return "Email sent successfully to: " + to;
        } catch (Exception e) {
            return "Error sending email: " + e.getMessage();
        }
    }

}